package vn.kiemviec.app;

import vn.kiemviec.app.fragments.NavFragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public abstract class TabActivity extends FragmentActivity{

	public interface OnTabChangedListener{
		public void TabChanged(int tabIndex);
	}
	
	public abstract NavFragment[] onInitTab();
	
	private NavFragment[] tabFragments;
	
	private int TabCount;
	private int currentTabIndex;
	
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);		
		tabFragments 	= onInitTab();
		TabCount		= tabFragments.length;
		initTabar();
		initLayout();
	}
	
	private void initTabar(){
		
		OnClickListener onTabClick = new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		};
		
		for(int i = 0;i<TabCount;i++){
			
		}
	}
	
	private void initLayout(){
		TabScreen screen = new TabScreen(this);
		setContentView(screen);
	}
	/**
	 * 
	 * @author TruongHieuNghia
	 *
	 */
	private class TabScreen extends ViewGroup{

		Tabbar bar;
		public TabScreen(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			setBackgroundColor(Color.GRAY);
			bar = new Tabbar(context);
			addView(bar);
		}

		@Override
		protected void onLayout(boolean changed, int l, int t, int r, int b) {
			// TODO Auto-generated method stub
			bar.layout(l, t, r, b);
		}
		
	}
	/**
	 * 
	 * @author TruongHieuNghia
	 *
	 */
	private class Tabbar extends ViewGroup{

		Button[] tabButton;
		public Tabbar(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
			setBackgroundColor(Color.GREEN);
			tabButton = new Button[TabCount];
			for(int i=0;i<TabCount;i++){
				addView(tabButton[i]);
			}
		}

		@Override
		protected void onLayout(boolean changed, int l, int t, int r, int b) {
			// TODO Auto-generated method stub
			for(int i=0;i<TabCount;i++){
				tabButton[i].layout(l, t, r, b);
			}
		}
		
	}
}
